package net.dotool;

import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Random;

import net.dotool.IoTools;

/**
 * 
 * @author 李岩飞
 * @email eliyanfei@126.com 2017年12月11日 下午3:53:23
 *
 */
public class EchartsTools {
	public static String buildEcharts(String path, Map<String, Object> dataMap) {
		final StringBuilder sb = new StringBuilder();
		try {
			List<String> list = IoTools.readFromTxt(new File(path), "filter=##","charset=utf-8");
			for (String s : list) {
				sb.append(s);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		String data = sb.toString();
		dataMap.put("index", new Random().nextInt(100000));
		for (String key : dataMap.keySet()) {
			data = data.replace("$" + key, String.valueOf(dataMap.get(key)));
		}
		return data;
	}
}
